from langchain_openai import ChatOpenAI
from langchain.prompts import (
    ChatPromptTemplate,
    SystemMessagePromptTemplate,
    MessagesPlaceholder,
    HumanMessagePromptTemplate,
)
from langchain.chains import ConversationChain
from langchain.memory import ConversationBufferMemory

prompt = ChatPromptTemplate.from_messages([
    SystemMessagePromptTemplate.from_template(
        """
        The following is a friendly conversation between a human and an AI.
        the AI is talkative and provides lots of specific details from its
        context.  if the AI does not know the answer to a question,
        it truthfully says it does not know.
        """
    ),
    MessagesPlaceholder(variable_name="history"),
    HumanMessagePromptTemplate.from_template("{input}")
])

llm = ChatOpenAI(temperature=0)

memory = ConversationBufferMemory(return_messages=True)

conversation = ConversationChain(memory=memory, prompt=prompt, llm=llm)

result = conversation.predict(input="你好，我是李特丽！")
print(result)

result = conversation.predict(input="我之前和你说过的我的名字是什么？")
print(result)